using System;
using System.Collections.Generic;
using System.Text;
using FireStarter.Base;
using FireStarter.CodeGeneration;
using FireStarter.CodeGeneration.Generator;
using FireStarter.Test.CodeGeneration.Generator;
using FireStarterModeller.BO;
using NUnit.Framework;

namespace FireStarter.Test.CodeGeneration.Generator
{
    [TestFixture]
    public class TestModelStrategyMapper
    {

        [Test]
        public void TestEmpty_ShouldRaiseError()
        {
            //---------------Set up test pack-------------------
            ModelStrategyMapper mapper = new ModelStrategyMapper();
            var type = typeof (object);
            //---------------Execute Test ----------------------
            try
            {
                mapper.GetStrategy(type);
                Assert.Fail("'ArgumentException' Should have thrown an error as there is nothing in the mapper");
            }
                //---------------Test Result -----------------------
            catch (ArgumentException ex)
            {
                StringAssert.Contains("No strategy exists for the given type: " + type.FullName, ex.Message);
            }
        }

        [Test]
        public void TestSimpleMatch()
        {
            //---------------Set up test pack-------------------
            ModelStrategyMapper mapper = new ModelStrategyMapper();
            var expectedStrategy = new GenerationStrategyStub();
            var storedType = typeof(string);
            mapper.SetStrategy(storedType, expectedStrategy);
            //---------------Assert Precondition----------------

            //---------------Execute Test ----------------------
            IGenerationStrategy strategy = mapper.GetStrategy(storedType);
            //---------------Test Result -----------------------
            Assert.AreSame(expectedStrategy, strategy);
        }   
        
        [Test]
        public void TestDirectBaseType()
        {
            //---------------Set up test pack-------------------
            ModelStrategyMapper mapper = new ModelStrategyMapper();
            var expectedStrategy = new GenerationStrategyStub();
            var storedType = typeof(object);
            mapper.SetStrategy(storedType, expectedStrategy);
            //---------------Assert Precondition----------------

            //---------------Execute Test ----------------------
            IGenerationStrategy strategy1 = mapper.GetStrategy(typeof(String));
            IGenerationStrategy strategy2 = mapper.GetStrategy(typeof(Int32));
            //---------------Test Result -----------------------
            Assert.AreSame(expectedStrategy, strategy1);
            Assert.AreSame(expectedStrategy, strategy2);
        }

        [Test]
        public void TestInterfaceBaseType()
        {
            //---------------Set up test pack-------------------
            ModelStrategyMapper mapper = new ModelStrategyMapper();
            var expectedStrategy = new GenerationStrategyStub();
            var storedType = typeof(IModelElement);
            mapper.SetStrategy(storedType, expectedStrategy);
            //---------------Assert Precondition----------------

            //---------------Execute Test ----------------------
            IGenerationStrategy strategy = mapper.GetStrategy(typeof(ModelElementStub));
            //---------------Test Result -----------------------
            Assert.AreSame(expectedStrategy, strategy);
        }
    }
}